#ifndef CADDENTRYDIALOG_H
#define CADDENTRYDIALOG_H

#include <QtGui/QDialog>

#include "src/ciconselectionmodel.h"
#include "src/centry.h"

#include <QtDebug>

#include "src/cdownloader.h"

namespace Ui {
    class CAddEntryDialog;
}

class CAddEntryDialog : public QDialog {
    Q_OBJECT
public:
    CAddEntryDialog(QString id, QString parent_name, QWidget *parent = 0);
    ~CAddEntryDialog();

    void setEntry(CEntry *e);

    QString id();
    QString creation();

    QMap<QString, QVariant> map() { return m_map; }
    QStringList blobs();

    bool isEdit() { return m_entry; }

protected:
    void changeEvent(QEvent *e);

private:
    Ui::CAddEntryDialog *m_ui;
    CIconSelectionModel *m_model;

    QString m_id;

    CEntry *m_entry;

    QMap<QString, QVariant> m_map;

    CDownloader *m_downloader;

    void debug(QString msg) const { qDebug() << "[AddEntryDialog]\t" + msg; }
    bool loadIcon(QByteArray&);

private slots:
    void checkFields();
    void showHidePassword(bool state);
    void openImage();
    void process();
    void downloadFavicon();
    void urlChanged(QString);
    void downloadFinished();

signals:
    void entry(CAddEntryDialog*);
};

#endif // CADDENTRYDIALOG_H
